package org.despair2D.ui.puppet 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.utils.getDefinitionByName;
	import org.despair2D.debug.Logger;
	import org.despair2D.renderer.IView;
	
	import org.despair2D.core.ns_despair;
	use namespace ns_despair;
	
	
public class DisplayObjectContainerPuppet extends PuppetProxy
{
	
	public function DisplayObjectContainerPuppet() 
	{
		super();
		m_view = new DisplayObjectContainerPuppetComp(this);
	}
	
	
	
	final public function addChild( child:DisplayObject ) : DisplayObject
	{
		return m_view.addChild(child)
	}
	
	final public function removeChild( child:DisplayObject ) : DisplayObject
	{
		return m_view.removeChild(child)
	}
	
	final public function addChildAt ( child:DisplayObject, index:int) : DisplayObject
	{
		return m_view.addChildAt(child, index)
	}
	
	final public function removeChildAt ( child:DisplayObject, index:int) : DisplayObject
	{
		return m_view.removeChildAt(index)
	}
	
	final public function getChildAt ( index:int) : DisplayObject
	{
		return m_view.getChildAt(index)
	}
	
	final public function getChildByName( name:String ) : DisplayObject
	{
		return m_view.getChildByName(name)
	}
	
	final public function getChildIndex( child:DisplayObject ) : int
	{
		return m_view.getChildIndex(child)
	}
	
	
	final override ns_despair function get view() : IView
	{
		return m_view;
	}
	
	
	final override ns_despair function recycle() : void
	{
		super.recycle();
		cachedList[cachedLength++] = this;
	}
	
	
	ns_despair static function getPuppet( cacheAsBitmap:Boolean ) : DisplayObjectContainerPuppet
	{
		var p:DisplayObjectContainerPuppet
		
		p = Boolean(cachedLength > 0 ? cachedLength-- : 0) ? cachedList.pop() : new DisplayObjectContainerPuppet();
		p.m_view.cacheAsBitmap = cacheAsBitmap
		
		return p
	}
	
	
	
	ns_despair static var cachedList:Array = [];
	
	ns_despair static var cachedLength:int;

	
	ns_despair var m_view:DisplayObjectContainerPuppetComp;
	
}

}

import org.despair2D.renderer.display.DisplayUtil;
import org.despair2D.ui.puppet.PuppetCompBase
import org.despair2D.ui.puppet.IPuppet

import org.despair2D.core.ns_despair;
use namespace ns_despair;
	
	
final class DisplayObjectContainerPuppetComp extends PuppetCompBase
{
	
	public function DisplayObjectContainerPuppetComp( proxy:IPuppet ) 
	{
		super(proxy);
	}
	
	
	final override ns_despair function recycle() : void
	{
		DisplayUtil.clear(this)
		super.recycle()
	}
	
}